﻿//------------------------------------------------------------------------------
// 创建标识: Copyright (C) 2008 Socansoft.com 版权所有
// 创建描述: SocanCode代码生成器自动创建于 2008-9-10 15:17:31
//
// 功能描述: 
//
// 修改标识: 
// 修改描述: 
//------------------------------------------------------------------------------

using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;

using DBUtility;
using System.Collections;
using System.Collections.Generic;


    /// <summary>
    /// 数据访问类 V_VIPSET
    /// </summary>
    public class V_VIPSET 
    {
        public V_VIPSET()
        { }

        #region  成员方法
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public string Add(Model.V_VIPSET model)
        {
            int rowsAffected;
            SqlParameter[] parameters = {
                    new SqlParameter("@DM", SqlDbType.VarChar,20),
                    new SqlParameter("@MC", SqlDbType.VarChar,50),
                    new SqlParameter("@ZJF", SqlDbType.VarChar,20),
                    new SqlParameter("@GKDM", SqlDbType.VarChar,20),
                    new SqlParameter("@XLDM", SqlDbType.VarChar,6),
                    new SqlParameter("@KLDM", SqlDbType.VarChar,6),
                    new SqlParameter("@LBDM", SqlDbType.VarChar,6),
                    new SqlParameter("@QDDM", SqlDbType.VarChar,6),
                    new SqlParameter("@QYDM", SqlDbType.VarChar,6),
                    new SqlParameter("@CKDM", SqlDbType.VarChar,6),
                    new SqlParameter("@BZ", SqlDbType.VarChar,100),
                    new SqlParameter("@QYBJ", SqlDbType.Char,1),
                    new SqlParameter("@TYBJ", SqlDbType.Char,1),
                    new SqlParameter("@QYRQ", SqlDbType.DateTime),
                    new SqlParameter("@JDRQ", SqlDbType.DateTime),
                    new SqlParameter("@XGRQ", SqlDbType.DateTime),
                    new SqlParameter("@TYRQ", SqlDbType.DateTime),
                    new SqlParameter("@ZK", SqlDbType.Decimal),
                    new SqlParameter("@XFJE", SqlDbType.Decimal),
                    new SqlParameter("@XFSL", SqlDbType.Int),
                    new SqlParameter("@TZBJ", SqlDbType.VarChar,6),
                    new SqlParameter("@TZJE", SqlDbType.Decimal),
                    new SqlParameter("@QYJF", SqlDbType.Int),
                    new SqlParameter("@JFJE", SqlDbType.Decimal),
                    new SqlParameter("@DQJF", SqlDbType.Int),
                    new SqlParameter("@BYZD1", SqlDbType.Char,1),
                    new SqlParameter("@BYZD2", SqlDbType.Char,1),
                    new SqlParameter("@BYZD3", SqlDbType.VarChar,20),
                    new SqlParameter("@BYZD4", SqlDbType.VarChar,20),
                    new SqlParameter("@BYZD5", SqlDbType.VarChar,20),
                    new SqlParameter("@BYZD6", SqlDbType.VarChar,150),
                    new SqlParameter("@BYZD7", SqlDbType.VarChar,150),
                    new SqlParameter("@BYZD8", SqlDbType.Int),
                    new SqlParameter("@BYZD9", SqlDbType.Int),
                    new SqlParameter("@BYZD10", SqlDbType.Int),
                    new SqlParameter("@BYZD11", SqlDbType.Float),
                    new SqlParameter("@BYZD12", SqlDbType.Float),
                    new SqlParameter("@BYZD13", SqlDbType.Float),
                    new SqlParameter("@BYZD14", SqlDbType.DateTime),
                    new SqlParameter("@BYZD15", SqlDbType.DateTime),
                    new SqlParameter("@ZK2", SqlDbType.Decimal),
                    new SqlParameter("@ZK_LIMIT", SqlDbType.Decimal),
                    new SqlParameter("@VERSION", SqlDbType.VarChar,10)
            };
            parameters[0].Value = model.DM;

            if (model.MC != null)
                parameters[1].Value = model.MC;
            else
                parameters[1].Value = DBNull.Value;


            if (model.ZJF != null)
                parameters[2].Value = model.ZJF;
            else
                parameters[2].Value = DBNull.Value;


            if (model.GKDM != null)
                parameters[3].Value = model.GKDM;
            else
                parameters[3].Value = DBNull.Value;


            if (model.XLDM != null)
                parameters[4].Value = model.XLDM;
            else
                parameters[4].Value = DBNull.Value;


            if (model.KLDM != null)
                parameters[5].Value = model.KLDM;
            else
                parameters[5].Value = DBNull.Value;


            if (model.LBDM != null)
                parameters[6].Value = model.LBDM;
            else
                parameters[6].Value = DBNull.Value;


            if (model.QDDM != null)
                parameters[7].Value = model.QDDM;
            else
                parameters[7].Value = DBNull.Value;


            if (model.QYDM != null)
                parameters[8].Value = model.QYDM;
            else
                parameters[8].Value = DBNull.Value;


            if (model.CKDM != null)
                parameters[9].Value = model.CKDM;
            else
                parameters[9].Value = DBNull.Value;


            if (model.BZ != null)
                parameters[10].Value = model.BZ;
            else
                parameters[10].Value = DBNull.Value;


            if (model.QYBJ != null)
                parameters[11].Value = model.QYBJ;
            else
                parameters[11].Value = DBNull.Value;


            if (model.TYBJ != null)
                parameters[12].Value = model.TYBJ;
            else
                parameters[12].Value = DBNull.Value;


            if (model.QYRQ != DateTime.MinValue)
                parameters[13].Value = model.QYRQ;
            else
                parameters[13].Value = DBNull.Value;


            if (model.JDRQ != DateTime.MinValue)
                parameters[14].Value = model.JDRQ;
            else
                parameters[14].Value = DBNull.Value;


            if (model.XGRQ != DateTime.MinValue)
                parameters[15].Value = model.XGRQ;
            else
                parameters[15].Value = DBNull.Value;


            if (model.TYRQ != DateTime.MinValue)
                parameters[16].Value = model.TYRQ;
            else
                parameters[16].Value = DBNull.Value;

            parameters[17].Value = model.ZK;
            parameters[18].Value = model.XFJE;
            parameters[19].Value = model.XFSL;

            if (model.TZBJ != null)
                parameters[20].Value = model.TZBJ;
            else
                parameters[20].Value = DBNull.Value;

            parameters[21].Value = model.TZJE;
            parameters[22].Value = model.QYJF;
            parameters[23].Value = model.JFJE;
            parameters[24].Value = model.DQJF;

            if (model.BYZD1 != null)
                parameters[25].Value = model.BYZD1;
            else
                parameters[25].Value = DBNull.Value;


            if (model.BYZD2 != null)
                parameters[26].Value = model.BYZD2;
            else
                parameters[26].Value = DBNull.Value;


            if (model.BYZD3 != null)
                parameters[27].Value = model.BYZD3;
            else
                parameters[27].Value = DBNull.Value;


            if (model.BYZD4 != null)
                parameters[28].Value = model.BYZD4;
            else
                parameters[28].Value = DBNull.Value;


            if (model.BYZD5 != null)
                parameters[29].Value = model.BYZD5;
            else
                parameters[29].Value = DBNull.Value;


            if (model.BYZD6 != null)
                parameters[30].Value = model.BYZD6;
            else
                parameters[30].Value = DBNull.Value;


            if (model.BYZD7 != null)
                parameters[31].Value = model.BYZD7;
            else
                parameters[31].Value = DBNull.Value;

            parameters[32].Value = model.BYZD8;
            parameters[33].Value = model.BYZD9;
            parameters[34].Value = model.BYZD10;
            parameters[35].Value = model.BYZD11;
            parameters[36].Value = model.BYZD12;
            parameters[37].Value = model.BYZD13;

            if (model.BYZD14 != DateTime.MinValue)
                parameters[38].Value = model.BYZD14;
            else
                parameters[38].Value = DBNull.Value;


            if (model.BYZD15 != DateTime.MinValue)
                parameters[39].Value = model.BYZD15;
            else
                parameters[39].Value = DBNull.Value;

            parameters[40].Value = model.ZK2;
            parameters[41].Value = model.ZK_LIMIT;

            if (model.VERSION != null)
                parameters[42].Value = model.VERSION;
            else
                parameters[42].Value = DBNull.Value;

            SqlHelper.RunProcedure(DB.WEBConnectionString, "sp_V_VIPSET_ADD", parameters, out rowsAffected);

            if (rowsAffected > 0)
                return model.DM;
            else
                return null;
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.V_VIPSET model)
        {
            int rowsAffected;
            SqlParameter[] parameters = {
                    new SqlParameter("@DM", SqlDbType.VarChar,20),
                    new SqlParameter("@MC", SqlDbType.VarChar,50),
                    new SqlParameter("@ZJF", SqlDbType.VarChar,20),
                    new SqlParameter("@GKDM", SqlDbType.VarChar,20),
                    new SqlParameter("@XLDM", SqlDbType.VarChar,6),
                    new SqlParameter("@KLDM", SqlDbType.VarChar,6),
                    new SqlParameter("@LBDM", SqlDbType.VarChar,6),
                    new SqlParameter("@QDDM", SqlDbType.VarChar,6),
                    new SqlParameter("@QYDM", SqlDbType.VarChar,6),
                    new SqlParameter("@CKDM", SqlDbType.VarChar,6),
                    new SqlParameter("@BZ", SqlDbType.VarChar,100),
                    new SqlParameter("@QYBJ", SqlDbType.Char,1),
                    new SqlParameter("@TYBJ", SqlDbType.Char,1),
                    new SqlParameter("@QYRQ", SqlDbType.DateTime),
                    new SqlParameter("@JDRQ", SqlDbType.DateTime),
                    new SqlParameter("@XGRQ", SqlDbType.DateTime),
                    new SqlParameter("@TYRQ", SqlDbType.DateTime),
                    new SqlParameter("@ZK", SqlDbType.Decimal),
                    new SqlParameter("@XFJE", SqlDbType.Decimal),
                    new SqlParameter("@XFSL", SqlDbType.Int),
                    new SqlParameter("@TZBJ", SqlDbType.VarChar,6),
                    new SqlParameter("@TZJE", SqlDbType.Decimal),
                    new SqlParameter("@QYJF", SqlDbType.Int),
                    new SqlParameter("@JFJE", SqlDbType.Decimal),
                    new SqlParameter("@DQJF", SqlDbType.Int),
                    new SqlParameter("@BYZD1", SqlDbType.Char,1),
                    new SqlParameter("@BYZD2", SqlDbType.Char,1),
                    new SqlParameter("@BYZD3", SqlDbType.VarChar,20),
                    new SqlParameter("@BYZD4", SqlDbType.VarChar,20),
                    new SqlParameter("@BYZD5", SqlDbType.VarChar,20),
                    new SqlParameter("@BYZD6", SqlDbType.VarChar,150),
                    new SqlParameter("@BYZD7", SqlDbType.VarChar,150),
                    new SqlParameter("@BYZD8", SqlDbType.Int),
                    new SqlParameter("@BYZD9", SqlDbType.Int),
                    new SqlParameter("@BYZD10", SqlDbType.Int),
                    new SqlParameter("@BYZD11", SqlDbType.Float),
                    new SqlParameter("@BYZD12", SqlDbType.Float),
                    new SqlParameter("@BYZD13", SqlDbType.Float),
                    new SqlParameter("@BYZD14", SqlDbType.DateTime),
                    new SqlParameter("@BYZD15", SqlDbType.DateTime),
                    new SqlParameter("@ZK2", SqlDbType.Decimal),
                    new SqlParameter("@ZK_LIMIT", SqlDbType.Decimal),
                    new SqlParameter("@VERSION", SqlDbType.VarChar,10)
            };
            parameters[0].Value = model.DM;

            if (model.MC != null)
                parameters[1].Value = model.MC;
            else
                parameters[1].Value = DBNull.Value;


            if (model.ZJF != null)
                parameters[2].Value = model.ZJF;
            else
                parameters[2].Value = DBNull.Value;


            if (model.GKDM != null)
                parameters[3].Value = model.GKDM;
            else
                parameters[3].Value = DBNull.Value;


            if (model.XLDM != null)
                parameters[4].Value = model.XLDM;
            else
                parameters[4].Value = DBNull.Value;


            if (model.KLDM != null)
                parameters[5].Value = model.KLDM;
            else
                parameters[5].Value = DBNull.Value;


            if (model.LBDM != null)
                parameters[6].Value = model.LBDM;
            else
                parameters[6].Value = DBNull.Value;


            if (model.QDDM != null)
                parameters[7].Value = model.QDDM;
            else
                parameters[7].Value = DBNull.Value;


            if (model.QYDM != null)
                parameters[8].Value = model.QYDM;
            else
                parameters[8].Value = DBNull.Value;


            if (model.CKDM != null)
                parameters[9].Value = model.CKDM;
            else
                parameters[9].Value = DBNull.Value;


            if (model.BZ != null)
                parameters[10].Value = model.BZ;
            else
                parameters[10].Value = DBNull.Value;


            if (model.QYBJ != null)
                parameters[11].Value = model.QYBJ;
            else
                parameters[11].Value = DBNull.Value;


            if (model.TYBJ != null)
                parameters[12].Value = model.TYBJ;
            else
                parameters[12].Value = DBNull.Value;


            if (model.QYRQ != DateTime.MinValue)
                parameters[13].Value = model.QYRQ;
            else
                parameters[13].Value = DBNull.Value;


            if (model.JDRQ != DateTime.MinValue)
                parameters[14].Value = model.JDRQ;
            else
                parameters[14].Value = DBNull.Value;


            if (model.XGRQ != DateTime.MinValue)
                parameters[15].Value = model.XGRQ;
            else
                parameters[15].Value = DBNull.Value;


            if (model.TYRQ != DateTime.MinValue)
                parameters[16].Value = model.TYRQ;
            else
                parameters[16].Value = DBNull.Value;

            parameters[17].Value = model.ZK;
            parameters[18].Value = model.XFJE;
            parameters[19].Value = model.XFSL;

            if (model.TZBJ != null)
                parameters[20].Value = model.TZBJ;
            else
                parameters[20].Value = DBNull.Value;

            parameters[21].Value = model.TZJE;
            parameters[22].Value = model.QYJF;
            parameters[23].Value = model.JFJE;
            parameters[24].Value = model.DQJF;

            if (model.BYZD1 != null)
                parameters[25].Value = model.BYZD1;
            else
                parameters[25].Value = DBNull.Value;


            if (model.BYZD2 != null)
                parameters[26].Value = model.BYZD2;
            else
                parameters[26].Value = DBNull.Value;


            if (model.BYZD3 != null)
                parameters[27].Value = model.BYZD3;
            else
                parameters[27].Value = DBNull.Value;


            if (model.BYZD4 != null)
                parameters[28].Value = model.BYZD4;
            else
                parameters[28].Value = DBNull.Value;


            if (model.BYZD5 != null)
                parameters[29].Value = model.BYZD5;
            else
                parameters[29].Value = DBNull.Value;


            if (model.BYZD6 != null)
                parameters[30].Value = model.BYZD6;
            else
                parameters[30].Value = DBNull.Value;


            if (model.BYZD7 != null)
                parameters[31].Value = model.BYZD7;
            else
                parameters[31].Value = DBNull.Value;

            parameters[32].Value = model.BYZD8;
            parameters[33].Value = model.BYZD9;
            parameters[34].Value = model.BYZD10;
            parameters[35].Value = model.BYZD11;
            parameters[36].Value = model.BYZD12;
            parameters[37].Value = model.BYZD13;

            if (model.BYZD14 != DateTime.MinValue)
                parameters[38].Value = model.BYZD14;
            else
                parameters[38].Value = DBNull.Value;


            if (model.BYZD15 != DateTime.MinValue)
                parameters[39].Value = model.BYZD15;
            else
                parameters[39].Value = DBNull.Value;

            parameters[40].Value = model.ZK2;
            parameters[41].Value = model.ZK_LIMIT;

            if (model.VERSION != null)
                parameters[42].Value = model.VERSION;
            else
                parameters[42].Value = DBNull.Value;


            SqlHelper.RunProcedure(SqlHelper.LocalSqlServer, "sp_V_VIPSET_Update", parameters, out rowsAffected);
            return rowsAffected > 0;
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string DM)
        {
            int rowsAffected;
            SqlParameter[] parameters = {
                    new SqlParameter("@DM", SqlDbType.VarChar,20)};
            parameters[0].Value = DM;

            SqlHelper.RunProcedure(SqlHelper.LocalSqlServer, "sp_V_VIPSET_Delete", parameters, out rowsAffected);
            return rowsAffected > 0;
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string DM)
        {
            int rowsAffected;
            SqlParameter[] parameters = {
                    new SqlParameter("@DM", SqlDbType.VarChar,20)};
            parameters[0].Value = DM;
            return SqlHelper.RunProcedure(SqlHelper.LocalSqlServer, "sp_V_VIPSET_Exists", parameters, out rowsAffected) == 1;
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.V_VIPSET GetModel(string DM)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@DM", SqlDbType.VarChar,20)};
            parameters[0].Value = DM;
            DataSet ds = SqlHelper.RunProcedure(SqlHelper.LocalSqlServer, "sp_V_VIPSET_GetModel", parameters, "ds");
            if (ds.Tables[0].Rows.Count > 0)
            {
                DataRow r = ds.Tables[0].Rows[0];
                return GetModel(r);
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获取泛型数据列表
        /// </summary>
        public IList<Model.V_VIPSET> GetList()
        {
            SqlParameter[] parameters ={ };
            DataSet ds = SqlHelper.RunProcedure(SqlHelper.LocalSqlServer, "sp_V_VIPSET_GetList", parameters, "ds");
            return GetList(ds.Tables[0]);
        }

        /// <summary>
        /// 分页获取泛型数据列表
        /// </summary>
        public IList<Model.V_VIPSET> GetList(int pageSize, int pageIndex, string fldSort, bool sort, string strCondition, out int pageCount, out int count)
        {
            string strSql;
            DataSet ds = SqlHelper.PageList(SqlHelper.LocalSqlServer, "[V_VIPSET]", null, pageSize, pageIndex, fldSort, sort, strCondition, "DM", false, out pageCount, out count, out strSql);
            return GetList(ds.Tables[0]);
        }
        #endregion

        /// <summary>
        /// 由一行数据得到一个实体
        /// </summary>
        private Model.V_VIPSET GetModel(DataRow r)
        {
            Model.V_VIPSET model = new Model.V_VIPSET();
            model.DM = SqlHelper.GetString(r["DM"]);
            model.MC = SqlHelper.GetString(r["MC"]);
            model.ZJF = SqlHelper.GetString(r["ZJF"]);
            model.GKDM = SqlHelper.GetString(r["GKDM"]);
            model.XLDM = SqlHelper.GetString(r["XLDM"]);
            model.KLDM = SqlHelper.GetString(r["KLDM"]);
            model.LBDM = SqlHelper.GetString(r["LBDM"]);
            model.QDDM = SqlHelper.GetString(r["QDDM"]);
            model.QYDM = SqlHelper.GetString(r["QYDM"]);
            model.CKDM = SqlHelper.GetString(r["CKDM"]);
            model.BZ = SqlHelper.GetString(r["BZ"]);
            model.QYBJ = SqlHelper.GetString(r["QYBJ"]);
            model.TYBJ = SqlHelper.GetString(r["TYBJ"]);
            model.QYRQ = SqlHelper.GetDateTime(r["QYRQ"]);
            model.JDRQ = SqlHelper.GetDateTime(r["JDRQ"]);
            model.XGRQ = SqlHelper.GetDateTime(r["XGRQ"]);
            model.TYRQ = SqlHelper.GetDateTime(r["TYRQ"]);
            model.ZK = SqlHelper.GetDecimal(r["ZK"]);
            model.XFJE = SqlHelper.GetDecimal(r["XFJE"]);
            model.XFSL = SqlHelper.GetInt(r["XFSL"]);
            model.TZBJ = SqlHelper.GetString(r["TZBJ"]);
            model.TZJE = SqlHelper.GetDecimal(r["TZJE"]);
            model.QYJF = SqlHelper.GetInt(r["QYJF"]);
            model.JFJE = SqlHelper.GetDecimal(r["JFJE"]);
            model.DQJF = SqlHelper.GetInt(r["DQJF"]);
            model.BYZD1 = SqlHelper.GetString(r["BYZD1"]);
            model.BYZD2 = SqlHelper.GetString(r["BYZD2"]);
            model.BYZD3 = SqlHelper.GetString(r["BYZD3"]);
            model.BYZD4 = SqlHelper.GetString(r["BYZD4"]);
            model.BYZD5 = SqlHelper.GetString(r["BYZD5"]);
            model.BYZD6 = SqlHelper.GetString(r["BYZD6"]);
            model.BYZD7 = SqlHelper.GetString(r["BYZD7"]);
            model.BYZD8 = SqlHelper.GetInt(r["BYZD8"]);
            model.BYZD9 = SqlHelper.GetInt(r["BYZD9"]);
            model.BYZD10 = SqlHelper.GetInt(r["BYZD10"]);
            model.BYZD11 = SqlHelper.GetDecimal(r["BYZD11"]);
            model.BYZD12 = SqlHelper.GetDecimal(r["BYZD12"]);
            model.BYZD13 = SqlHelper.GetDecimal(r["BYZD13"]);
            model.BYZD14 = SqlHelper.GetDateTime(r["BYZD14"]);
            model.BYZD15 = SqlHelper.GetDateTime(r["BYZD15"]);
            model.ZK2 = SqlHelper.GetDecimal(r["ZK2"]);
            model.ZK_LIMIT = SqlHelper.GetDecimal(r["ZK_LIMIT"]);
            model.VERSION = SqlHelper.GetString(r["VERSION"]);
            return model;
        }

        /// <summary>
        /// 由数据集得到泛型数据列表
        /// </summary>
        public IList<Model.V_VIPSET> GetList(DataTable dt)
        {
            List<Model.V_VIPSET> l = new List<Model.V_VIPSET>();
            foreach (DataRow r in dt.Rows)
            {
                l.Add(GetModel(r));
            }
            return l;
        }
    }

